/**
 * 
 */
package es.ibm.santillana.mdm.workflow.comun;


import java.util.Iterator;

import com.ibm.pim.attribute.AttributeInstance;
import com.ibm.pim.catalog.Catalog;
import com.ibm.pim.catalog.CatalogManager;
import com.ibm.pim.catalog.item.Item;
import com.ibm.pim.collaboration.CollaborationItem;
import com.ibm.pim.collaboration.CollaborationStep;
import com.ibm.pim.collaboration.ItemCollaborationArea;
import com.ibm.pim.collection.PIMCollection;
import com.ibm.pim.common.ExtendedValidationErrors;
import com.ibm.pim.common.exceptions.PIMInvalidOperationException;
import com.ibm.pim.context.Context;
import com.ibm.pim.context.PIMContextFactory;
import com.ibm.pim.extensionpoints.WorkflowStepFunction;
import com.ibm.pim.extensionpoints.WorkflowStepFunctionArguments;
import com.ibm.pim.utils.Logger;

import es.ibm.santillana.mdm.common.bussinesmodel.ConfigModel;
import es.ibm.santillana.mdm.common.bussinesmodel.WorkflowManagement;
import es.ibm.santillana.mdm.common.util.ConstSantillana;
import es.ibm.santillana.mdm.common.util.SantillanaLogger;

/**
 * @author Benito
 *
 */
public class Initial implements WorkflowStepFunction {

	/**
	 * 
	 */
	public Initial() {
		// TODO Auto-generated constructor stub
	}

	/* (non-Javadoc)
	 * @see com.ibm.pim.extensionpoints.WorkflowStepFunction#in(com.ibm.pim.extensionpoints.WorkflowStepFunctionArguments)
	 */
	@Override
	public void in(WorkflowStepFunctionArguments arg0) {
		// TODO Auto-generated method stub
		Logger log = SantillanaLogger.getLogger();
		System.out.println("IN del paso initial ");
		PIMCollection <CollaborationItem> collabItems = arg0.getItems();
		Iterator <CollaborationItem> it = collabItems.iterator();
		ItemCollaborationArea itmColArea = (ItemCollaborationArea) arg0.getCollaborationStep().getCollaborationArea();
		
		while (it.hasNext()) {
			CollaborationItem itmCol = it.next();
			//Un usuario que no sea del pais no puede hacer checkout, si lo hace sacamos el item
			Boolean bValidtoEntry = ConfigModel.isItemAvaibleInUserCountry(itmCol);

			if (!bValidtoEntry){
				System.out.println("Voy a borrarlo");
				itmColArea.drop(itmCol);
				try {
					Thread.sleep(1000);
				} catch (InterruptedException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			}
		}
	}

	/* (non-Javadoc)
	 * @see com.ibm.pim.extensionpoints.WorkflowStepFunction#out(com.ibm.pim.extensionpoints.WorkflowStepFunctionArguments)
	 */
	@Override
	public void out(WorkflowStepFunctionArguments arg0) {}

	/* (non-Javadoc)
	 * @see com.ibm.pim.extensionpoints.WorkflowStepFunction#timeout(com.ibm.pim.extensionpoints.WorkflowStepFunctionArguments)
	 */
	@Override
	public void timeout(WorkflowStepFunctionArguments arg0) {
		// TODO Auto-generated method stub

	}

}
